/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rafkind.resrev.web.page.component;

import com.rafkind.resrev.web.page.component.CalendarPanel.Day;
import com.rafkind.resrev.web.page.component.CalendarPanel.Day.StyledMessage;
import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

/**
 *
 * @author dave
 */
public class CalendarDayBox extends Panel {

  public CalendarDayBox(String id, IModel<Day> model) {
    super(id, model);   
    
    Day d = model.getObject();
      
    WebMarkupContainer day = new WebMarkupContainer("day");
    
    Label date = new Label("date", new Model(d.getDay()));
    Label dayName = new Label("dayName", d.getName());
    dayName.setVisible(d.getName() != null);
    
    day.add(date);
    day.add(dayName);
    
    day.add(new ListView<StyledMessage>("messages", d.getMessages()){
      @Override
      protected void populateItem(ListItem<StyledMessage> item) {
        StyledMessage cm = item.getModelObject();
        
        item.add(new Label("message", cm.getMessage())
            .add(new SimpleAttributeModifier(
              "style", cm.getStyle())));
      }            
    });
    
    add(day);    
  }
}